home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / tcl / extend / tests / dup.test < prev    next >
Encoding:
Text File  |  1993-10-26  |  2.3 KB  |  93 lines  |  [TEXT/MPS ]

  1. #
  2. # dup.test
  3. #
  4. # Tests for the dup command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: dup.test,v 2.3 1993/07/20 08:35:45 markd Exp $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21.  
  22. # Create a test file
  23.  
  24. unlink -nocomplain {DUP.TMP DUP2.TMP}
  25.  
  26. set testFH [open DUP.TMP w]
  27. for {set cnt 0} {$cnt < 100} {incr cnt} {
  28.      puts $testFH [GenRec $cnt]
  29. }
  30. close $testFH
  31.  
  32. Test dup-1.1 {dup tests} {
  33.     set testFH [open DUP.TMP]
  34.     set testFH2 [dup $testFH]
  35.     gets $testFH2 testRec
  36.     close $testFH
  37.     close $testFH2
  38.     set testRec
  39. } 0 [GenRec 0]
  40.  
  41. Test dup-1.2 {dup tests} {
  42.     set testFH [open DUP.TMP]
  43.     set testFH2 [open DUP2.TMP w]
  44.     set testFH2 [dup $testFH $testFH2]
  45.     gets $testFH2 testRec
  46.     close $testFH
  47.     close $testFH2
  48.     set testRec
  49. } 0 [GenRec 0]
  50.  
  51. set data {{now is the time}    {for all good programmers} 
  52.           {to come to the aid} {of their software}}
  53. set inFH [open INCMDS.TMP w]
  54. catch {unlink OUTPUT.TMP}
  55. foreach line $data {
  56.     puts $inFH "puts stdout \"$line\""
  57. }
  58. puts $inFH {flush stdout}
  59. puts $inFH {exit 0}
  60. close $inFH
  61.  
  62. flush stdout
  63. flush stderr
  64.  
  65. if {[set childPid [fork]] == 0} {
  66.     set inFH  [open INCMDS.TMP r]
  67.     set outFH [open OUTPUT.TMP w]
  68.  
  69.     dup $inFH stdin
  70.     close $inFH
  71.  
  72.     dup $outFH stdout
  73.     close $outFH
  74.         
  75.     execl ../tclmaster/bin/tcl [list -qc {commandloop {return ""} {return ""}}]
  76.     error "Should never make it here"
  77. }
  78.  
  79. Test dup-1.3 {dup tests} {
  80.     wait $childPid
  81. } 0 "$childPid EXIT 0"
  82.  
  83. set outFH [open OUTPUT.TMP r]
  84. foreach line $data {
  85.     Test dup-1.4 {dup tests} {
  86.         gets $outFH
  87.     } 0 $line
  88. }
  89. close $outFH
  90.  
  91. unlink -nocomplain {DUP.TMP DUP2.TMP INCMDS.TMP OUTPUT.TMP}
  92.  
  93.